﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using PowerCreator.LMS.Common.Script;

public partial class sysadmin_CountManager_CourseInfo : PowerCreator.LMS.Web.Base.BasePage
{
    //ManagerCourseInfo Course = new ManagerCourseInfo();
    //ManagerCourseType CourseType = new ManagerCourseType();

    #region View 视图查询
   
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!GetRole(PowerCreator.LMS.Model.Entity.Role.CountCourse))
        //{
        //    Script.ShowAndHistory("您没有课程统计的权限!", -1);
        //    return;
        //}

        if (!IsPostBack)
        {
            BinderCourseType();

            string search = GetSearch();
            BinderPager(search);
            BinderGV(search,1);
        }
    }

    private string GetSearch()
    {
        StringBuilder sbSearch = new StringBuilder();

        if (ddlCourseType.SelectedValue != "0")
        {
            sbSearch.Append(string.Format("CourseTypeID={0} and ", ddlCourseType.SelectedValue));
        }
        if (!string.IsNullOrEmpty(txtCourseName.Text))
        {
            sbSearch.Append(string.Format("CourseName like '%{0}%' and ",txtCourseName.Text));
        }
        sbSearch.Append(" 1=1 ");        
        return sbSearch.ToString();
    }
    private void BinderPager(string search)
    {
        //AspNetPager1.RecordCount = Course.ViewCourseResourceCount(search);
        //AspNetPager1.PageSize = FBasePage.PageSize();
    }    
    private void BinderGV(string search,int pageIndex)
    {
        //DataTable dt = new DataTable();
        //dt = Course.ViewCouresResourceQuery(search,FBasePage.PageSize(),pageIndex);
        //ViewState["dt"] = dt;       
        //gvCourseReport.DataSource = dt;
        //gvCourseReport.DataBind();
    }
    private void BinderCourseType()
    {
        //DataTable dt = CourseType.Query("");
        //BinderCourseType(dt, 0);

        //ListItem li = new ListItem();
        //li.Text = "不限分类";
        //li.Value = "0";
        //ddlCourseType.Items.Insert(0,li);
    }

    private void BinderCourseType(DataTable dt, int parentTypeid)
    {
        ////该方法被BinderCatalog()调用
        //DataView dv = new DataView(dt);
        //dv.RowFilter = "ParentTypeID=" + parentTypeid.ToString();  //过滤
        //ListItem li = new ListItem();
        //int layer = 0;
        //foreach (DataRowView drv in dv)
        //{
        //    layer = int.Parse(drv["Level"].ToString().Trim());
        //    string span = "";
        //    if (layer != 0)
        //    {
        //        for (int j = 0; j < layer; j++)
        //        {
        //            span += "　";
        //        }
        //        span += "|-";
        //    }

        //    li = new ListItem();
        //    li.Text = span + drv["TypeName"].ToString();
        //    li.Value = drv["TypeID"].ToString();
        //    ddlCourseType.Items.Add(li);
        //    BinderCourseType(dt, int.Parse(drv["TypeID"].ToString()));
        //}
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();      
        BinderGV(search, AspNetPager1.CurrentPageIndex);
    }
    protected void btnExport_Click(object sender, EventArgs e)
    {
        
        DataTable dt = (DataTable)ViewState["dt"];
        ExportList(dt);
    }
    protected void gvCourseReport_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[3].Text == "&nbsp;")
                e.Row.Cells[3].Text = "0";
        }
    }
    protected void btnAllCoursePass_Click(object sender, EventArgs e)
    {
        string url = "AllCoursePass.aspx";
        Script.RedirectURL(url);
    }
    private void ExportList(DataTable dt)
    {
        //ArrayList list = new ArrayList();
        //for (int i = 0; i < dt.Columns.Count; i++)
        //{
        //    if (dt.Columns[i].ColumnName == "CourseName")
        //    {
        //        dt.Columns[i].ColumnName = "课程名称";
        //        dt.Columns[i].SetOrdinal(0);
        //    }
        //    else if (dt.Columns[i].ColumnName == "PrelectTeacherName")
        //    {
        //        dt.Columns[i].ColumnName = "主讲教师";
        //        dt.Columns[i].SetOrdinal(1);
        //    }
        //    else if (dt.Columns[i].ColumnName == "CourseResourceCount")
        //    {
        //        dt.Columns[i].ColumnName = "资源总量";
        //        dt.Columns[i].SetOrdinal(2);
        //    }
        //    else if (dt.Columns[i].ColumnName == "CourseBroweCount")
        //    {
        //        dt.Columns[i].ColumnName = "课程点击量";
        //        dt.Columns[i].SetOrdinal(3);
        //    }
        //    else
        //    {
        //        list.Add(dt.Columns[i].ColumnName);
        //    }

        //}
        //for (int i = 0; i < list.Count; i++)
        //{
        //    dt.Columns.Remove(list[i].ToString());
        //}
        //Excel objExcel = new Excel();
        //objExcel.ToExcel(dt, this.Page, "课程统计", "课程统计信息", "CourseInfo");
    }
    protected void btnExport_All_Click(object sender, EventArgs e)
    {
        //string search = GetSearch();
        //DataTable dt = new DataTable();
        //dt = Course.ViewCouresResourceQuery(search, Course.ViewCourseResourceCount(search), 1);
        //ExportList(dt);
    }
}
